package ferramentas;

import java.awt.Rectangle;
import java.util.Vector;

import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.ScrollPaneConstants;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;

import presistencia.ItensConsulta;


public class GridObras
{
    private	String[] grdColunas;
    private	String[][] grdLinhas;
    private JPanel panel = new JPanel();
    private JTable table = new JTable();
    private DefaultTableModel defaultTableModel = new DefaultTableModel();
    private JScrollPane scroll;
	
    public GridObras(String[][] grdLinhas, String[] grdColunas)
    {
        this.grdColunas = grdColunas;
        this.grdLinhas = grdLinhas;
        loadData();
    }
    
    private void loadData()
    {
        defaultTableModel.setDataVector(grdLinhas, grdColunas);
        table.setModel(defaultTableModel);
        table.setBorder(BorderFactory.createEtchedBorder());
        table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        int vert = ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;
        int horz = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS;
                    
        table.getColumnModel().getColumn(0).setPreferredWidth(100);
        table.getColumnModel().getColumn(1).setPreferredWidth(200); 
        table.getColumnModel().getColumn(2).setPreferredWidth(300); 
        table.getColumnModel().getColumn(3).setPreferredWidth(100); 
        table.getColumnModel().getColumn(4).setPreferredWidth(100); 
        table.getColumnModel().getColumn(5).setPreferredWidth(200); 
        table.getColumnModel().getColumn(6).setPreferredWidth(100); 
        table.getColumnModel().getColumn(7).setPreferredWidth(100); 
        
        scroll = new JScrollPane(table, vert, horz);
        scroll.setViewportView(table);        
        scroll.setAutoscrolls(true);
        
        panel.add(scroll);
    }

	public JPanel getPanel() 
	{
		return panel;
	}

	public JTable getTable() 
	{
		return table;
	}

	public DefaultTableModel getDefaultTableModel() 
	{
		return defaultTableModel;
	}

	public JScrollPane getScroll() 
	{
		return scroll;
	}
}